package com.yxb.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.system.domain.Notification;
import com.yxb.system.service.INotificationService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 系统消息通知Controller
 * 
 * @author ruoyi
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/system/notification")
public class NotificationController extends BaseController
{
    @Autowired
    private INotificationService notificationService;

    /**
     * 查询系统消息通知列表
     */
    @PreAuthorize("@ss.hasPermi('system:notification:list')")
    @GetMapping("/list")
    public TableDataInfo list(Notification notification)
    {
        startPage();
        List<Notification> list = notificationService.selectNotificationList(notification);
        return getDataTable(list);
    }

    /**
     * 导出系统消息通知列表
     */
    @PreAuthorize("@ss.hasPermi('system:notification:export')")
    @Log(title = "系统消息通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notification notification)
    {
        List<Notification> list = notificationService.selectNotificationList(notification);
        ExcelUtil<Notification> util = new ExcelUtil<Notification>(Notification.class);
        util.exportExcel(response, list, "系统消息通知数据");
    }

    /**
     * 获取系统消息通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notification:query')")
    @GetMapping(value = "/{msgId}")
    public AjaxResult getInfo(@PathVariable("msgId") Long msgId)
    {
        return success(notificationService.selectNotificationByMsgId(msgId));
    }

    /**
     * 新增系统消息通知
     */
    @PreAuthorize("@ss.hasPermi('system:notification:add')")
    @Log(title = "系统消息通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notification notification)
    {
        return toAjax(notificationService.insertNotification(notification));
    }

    /**
     * 修改系统消息通知
     */
    @PreAuthorize("@ss.hasPermi('system:notification:edit')")
    @Log(title = "系统消息通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notification notification)
    {
        return toAjax(notificationService.updateNotification(notification));
    }

    /**
     * 删除系统消息通知
     */
    @PreAuthorize("@ss.hasPermi('system:notification:remove')")
    @Log(title = "系统消息通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{msgIds}")
    public AjaxResult remove(@PathVariable Long[] msgIds)
    {
        return toAjax(notificationService.deleteNotificationByMsgIds(msgIds));
    }
}
